package serve;

import Common.Message;
import Common.MessageType;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectOutputStream;

/*
处理消息
 */
public class MessageClientService {
    public void sendMessageToOne(String content,String sendId,String getterId){
        //1.组装信息对象
        Message message=new Message();
        message.setContent(content);
        message.setSender(sendId);
        message.setReceiver(getterId);
        message.setMsgType(MessageType.MESSAGE_COMMON);
        //提示
        System.out.println("我对："+getterId+"说"+content);
        //2.消息给服务器
         //先获取线程
        try {
            new ObjectOutputStream(ManageClientConnectServeThread.getClientConnectServiceThread(sendId).getSocket().getOutputStream()).writeObject(message);
        }catch (Exception e){
            e.getMessage();
        }

    }
    public void sendAll(String content,String senderId) {
        Message message = new Message();
        message.setContent(content);
        message.setSender(senderId);
        message.setMsgType(MessageType.MESSAGE_COMMON_ALL);
        System.out.println("我对大家说" + content);
        try {
            new ObjectOutputStream(ManageClientConnectServeThread.getClientConnectServiceThread(senderId).getSocket().getOutputStream()).writeObject(message);      
        } catch (Exception e) {
            e.getMessage();
        }
    }
        }


